﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.mainmenu {
    import flash.events.*;
    import reprise.controls.*;
    import org.robotlegs.core.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.views.components.mainmenu.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class MainMenuMediator extends Mediator implements IMediator {

		[Inject]
        public var mainMenu:MainMenu;
		[Inject]
        public var gameStateModel:GameStateModel;
		[Inject]
        public var languageModel:LanguageModel;
		[Inject]
        public var friendsModel:FriendsModel;
		[Inject]
        public var roomSlotsModel:RoomSlotsModel;
		[Inject]
        public var achievementModel:AchievementModel;
		[Inject]
        public var collectionModel:CollectableModel;
		[Inject]
        public var sessionModel:SessionModel;
		[Inject]
        public var worldModel:WorldModel;

        override public function onRegister():void{
            eventMap.mapListener(eventDispatcher, EventConstants.SELECT_MENU_TAB, this.selectMenuTab);
            eventMap.mapListener(eventDispatcher, EventConstants.UPDATE_ACHIEVEMENTS, this.onUpdateAchievements);
            eventMap.mapListener(eventDispatcher, EventConstants.SHOW_MAIN_MENU, this.showMenu);
            eventMap.mapListener(eventDispatcher, EventConstants.HIDE_MAIN_MENU, this.hideMenu);
            eventMap.mapListener(eventDispatcher, EventConstants.SHOW_MAIN_MENU_INVENTORY_ONLY, this.showInventoryOnly);
            eventMap.mapListener(eventDispatcher, EventConstants.SHOW_PATIENT_TAB_BUTTON, this.showPatientTabButton);
            eventMap.mapListener(eventDispatcher, EventConstants.HIDE_PATIENT_TAB_BUTTON, this.hidePatientTabButton);
            eventMap.mapListener(eventDispatcher, EventConstants.SHOW_SHOP_TAB_BUTTON, this.showShopTabButton);
            eventMap.mapListener(eventDispatcher, EventConstants.HIDE_SHOP_TAB_BUTTON, this.hideShopTabButton);
            eventMap.mapListener(eventDispatcher, EventConstants.KIOSK_AVAILABLE, this.kioskAvailable);
            eventMap.mapListener(eventDispatcher, CommandConstants.ADD_FRIENDS, this.enableGiftButton);
            eventMap.mapListener(eventDispatcher, EventConstants.INIT_WORLD_COMPLETE, this.initWorldComplete);
            eventMap.mapListener(eventDispatcher, EventConstants.COLLECTIONS_UPDATE, this.updateNumberOfCompletedCollections);
            eventMap.mapListener(this.mainMenu.giftsButton, MouseEvent.CLICK, this.giftButton_click);
            eventMap.mapListener(this.mainMenu.achievementButton, MouseEvent.CLICK, this.achievementsButton_clicked);
            eventMap.mapListener(this.mainMenu.collectionButton, MouseEvent.CLICK, this.collectionButton_clicked);
            eventMap.mapListener(this.mainMenu.tabRadioButtonGroup, Event.CHANGE, this.onTabChanged);
            if (this.gameStateModel.state == GameStateModel.STATE_GAME_TUTORIAL){
                this.hideMenu();
            };
            this.kioskAvailable();
            this.mainMenu.setLabels(this.languageModel.getTextByKey("friends_logo"), this.languageModel.getTextByKey("pets_logo"), this.languageModel.getTextByKey("inventory_logo"));
            this.mainMenu.giftsButton.setTooltipData(this.languageModel.getTextByKey("gift_logo_tooltip"));
            this.mainMenu.achievementButton.setLabel(this.languageModel.getTextByKey("achievements_logo"));
            this.mainMenu.collectionButton.setLabel(this.languageModel.getTextByKey("collections_logo"));
            this.mainMenu.shopButton.setLabel(this.languageModel.getTextByKey("customize_menu_logo"));
        }
        private function kioskAvailable(_arg1:Event=null):void{
            var _local2:Boolean = this.worldModel.hasAreaType(GameConstants.TYPE_KIOSK);
            ((_local2) && (this.mainMenu.setInventoryButtonVisible(true)));
        }
        private function onUpdateAchievements(_arg1:Event):void{
            this.mainMenu.setNumberOfAchievements(this.achievementModel.getNumberOfNotCollectedReachedRewards());
        }
        private function collectionButton_clicked(_arg1:MouseEvent):void{
            var _local2:Object = {type:"interface", subtype1:"collection"};
            this.track(_local2);
            dispatch(new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.COLLECTION_POPUP));
        }
        private function achievementsButton_clicked(_arg1:MouseEvent):void{
            var _local2:Object = new Object();
            _local2.type = "interface";
            _local2.st1 = "achievements";
            _local2.st2 = this.achievementModel.getNumberOfNotCollectedReachedRewards();
            this.track(_local2);
            dispatch(new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.ACHIEVEMENT_BOOK_POPUP));
        }
        private function giftButton_click(_arg1:MouseEvent):void{
            var _local2:Object = {type:"interface", subtype1:"gift"};
            this.track(_local2);
            dispatch(new InfoEvent(EventConstants.SHOW_GIFTS_POPUP, null));
        }
        private function onTabChanged(_arg1:Event):void{
            var _local2:RadioButtonGroup = RadioButtonGroup(_arg1.currentTarget);
            var _local3:String = _local2.selectedRadioButton().data();
            var _local4:Object = {type:"interface", subtype1:_local3};
            this.track(_local4);
        }
        private function initWorldComplete(_arg1:Event):void{
            this.updateNumberOfAvailableSlots();
            this.updateNumberOfCompletedCollections();
            eventMap.mapListener(eventDispatcher, UserModelEvent.ON_MODEL_CHANGED, this.onUserModelChanged);
        }
        private function onUserModelChanged(_arg1:UserModelEvent):void{
            this.updateNumberOfAvailableSlots();
            this.updateNumberOfCompletedCollections();
        }
        private function updateNumberOfAvailableSlots():void{
            var _local1:int = this.roomSlotsModel.freeSlots;
            this.mainMenu.setNumberOfFreeSlots(_local1);
        }
        private function updateNumberOfCompletedCollections(_arg1:Event=null):void{
            var _local2:int = this.collectionModel.numberOfCompletedCollections;
            this.mainMenu.setNumberOfCompletedCollections(_local2);
        }
        private function hideShopTabButton(_arg1:Event):void{
            this.mainMenu.setShopButtonVisible(false);
        }
        private function showShopTabButton(_arg1:Event):void{
            this.mainMenu.setShopButtonVisible(true);
        }
        private function hidePatientTabButton(_arg1:Event):void{
            this.mainMenu.setPatientButtonVisible(false);
        }
        private function showPatientTabButton(_arg1:Event):void{
            this.mainMenu.setPatientButtonVisible(true);
        }
        private function selectMenuTab(_arg1:InfoEvent):void{
            this.mainMenu.switchTab(_arg1.id);
        }
        private function enableGiftButton(_arg1:Event):void{
            var _local2 = (this.friendsModel.friends.length > 0);
            this.mainMenu.setGiftButtonVisible(_local2);
        }
        private function showInventoryOnly(_arg1:Event):void{
            this.mainMenu.showInventoryOnly();
        }
        private function showMenu(_arg1:Event):void{
            this.mainMenu.showAll();
        }
        private function hideMenu(_arg1:Event=null):void{
            this.mainMenu.hide();
        }
        private function track(_arg1:Object):void{
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.EVENT, _arg1));
        }

    }
}//package net.wooga.pets.views.mainmenu 
